<?php
    require_once dirname(__FILE__).'/../../class/address.class.php';
    require_once dirname(__FILE__).'/../../class/rice.class.php';
    $addressObj=new address;
    
    $farmID=$_GET["farmID"];
    $farmClass=new farm();
    $farmClass->setFarmID($farmID);
    $farm=$farmClass->getFarm();
    $memID=$farm["memID"];
    
    $memberClass=new member($memID);
    $member=$memberClass->getMember();
    
    $dateClass=new date();
    ?>
<style type="text/css">
    #structureContent{
        vertical-align: top;
    }
    #cropManageDIV{
        padding: 5px;
        overflow: auto;
    }
</style>
<div class="col-md-12" style="margin-top: 10px;">
    <div class="panel panel-default">
        <div class="panel-body">
            <?=$member["title"]." ".$member["firstName"]." ".$member["lastName"]?>
            <button class="btn btn-default" onclick="window.open('?page=member/farm/farm&memID=55','_self')" style="float: right;">
                <span class="glyphicon glyphicon-chevron-left"></span> เลือกแปลงนา
            </button>
        </div>
    </div>
</div>
<div class="col-md-12">
    <div class="panel panel-default">
        <div class="panel-heading">
            แปลงนา <?=$farm["farmName"]?>
            <button class="btn btn-default" style="float: right;"
                onclick="window.open('?page=member/farm/addFarmForm&memID=<?=$memID?>&farmID=<?=$farmID?>','_self')"
                >
                <div class="glyphicon glyphicon-pencil" style="float: left;margin-right: 5px;"></div>แก้ไข <?=$farm["farmName"]?>
            </button>
        </div>
        <div class="panel-body">
            <div class="col-md-12" style="margin-bottom: 10px">
                <?php
                    $subDistrict=$addressObj->getSubDistrict($farm["subDistrictID"]);
                    $district=$addressObj->getDistrict($farm["districtID"]);
                    $province=$addressObj->getProvince($farm["provinceID"]);
                ?>
                <?=$farm["farmName"]?> &nbsp;&nbsp;&nbsp;<?=$farm["area"]?> ไร่
                <div style="font-size: 80%;">
                    <?=$farm["address"]?> 
                    ตำบล <?=$subDistrict["subDistrictName"]?>
                    อำเภอ <?=$district["districtName"]?>
                    จังหวัด <?=$province["provinceName"]?>
                </div>
            </div>
            
            <?php
                $query="
                    select      *
                    from        member_farm_crop
                    where       farmID='".$farmID."'
                    order by    startDate asc
                    ";
                $result=$mysqli->query($query);
                $i=1;
                while($row=$result->fetch_array(MYSQLI_ASSOC)){
                    $riceObj= new rice($row["rvID"]);
                    $rice=$riceObj->getRice($row["rvID"]);
                    ?>
            <div class="col-md-6">
                <div class="btn btn-default" style="position: relative;width: 100%;margin-bottom: 5px;"
                    onclick="window.open('./?page=member/crop/cropCostInput&cropID=<?=$row["cropID"]?>','_self')"
                    >
                    <div style="position: absolute;font-size: 60%;">CROP <?=$i;?></div>
                    <?php
                        echo $dateClass->dateEncodeBE($row["startDate"]);
                        echo "-";
                        echo $dateClass->dateEncodeBE($row["endDate"]);
                    ?>
                    <div class="pull-right" style="font-weight: bold;"><?=$rice["rvName"]?></div>
                </div>
            </div>
                        <?php
                    $i++;
                }
            ?>
        </div>
    </div>
</div>
<div id="registButton"
    onclick="
        window.open('?page=member/crop/addCropForm&farmID=<?=$farmID?>','_self');
        /*$('#addCropDIV').show();
        $('#map-canvas').show();
        geoLocation='<?=$farm["geoLocation"]?>';
        setMap();*/
    "
    style="
        position: fixed;
        background-color: #A1D1FF;
        border-radius: 100px;
        color: #fff;
        width: 70px;
        height: 70px;
        bottom: 40px;
        right: 10px;
        cursor: pointer;
        box-shadow: 1px 1px 3px #000;
        ">
    <table class="noSpacing" style="width:100%;height: 100%;">
        <tr>
            <td style="text-align: center;vertical-align: middle;font-size: 30px">
                <img src="img/add.png" height="40">
            </td>
        </tr>
    </table>
</div>
<div id="addCropDIV" 
    style="
        display: none;
        position: fixed;
        top:0px;
        left: 0px;
        width: 100%;
        height: 100%;
        background-color: rgba(0,0,0,0.5);
        overflow: auto;
        ">
    <table class="noSpacing" style="width: 100%;height: 100%;">
        <tr>
            <td style="vertical-align: middle;height: 100%;">
                <div id="addFarmSubDIV" class="box-wrap" style="margin-left: auto;margin-right: auto;width: 500px;">
                    <div class="box-heading">
                        <h4>
                            <i class="icon-tag"></i> 
                            <span class="glyphicon glyphicon-plus"></span>
                            เพิ่มครอป
                            <span class="glyphicon glyphicon-remove" style="float: right;cursor: pointer;" onclick="$('#addCropDIV').hide()"></span>
                        </h4>
                    </div>
                    <div class="box-inner">
                        <form method="post" id="addCropForm" class="form-horizontal" action="member/crop/addCrop.php">
                            <input type="hidden" name="cropID" value="<?=$_GET["cropID"]?>">
                            <input type="hidden" id="farmID" name="farmID" value="<?=$_GET["farmID"]?>">
                            <fieldset>

                                <!-- Text input-->
                                <div class="form-group">
                                    <label class="col-md-4 control-label" for="farmName">ข้อมูลแปลง</label>  
                                    <div class="col-md-4">
                                        <b><?=$farm["farmName"]?></b> พื้นที่ <?=$farm["area"]?> ไร่<br>
                                        <?php
                                            $address=$farmClass->getFarmAddress();
                                            print_r($address);
                                        ?>
                                    </div>
                                </div>
                                
                                <div class="form-group">
                                    <label class="col-md-4 control-label" for="farmName">ช่วงเวลาที่ปลูก</label>  
                                    <div class="col-md-4">
                                        <input id="startDate" name="startDate" class="form-control input-md" type="text" style="width:auto;float:left;margin-right: 5px;width: 100px">
                                        <div style="margin-top: 5px;margin-left: 15px;margin-right: 15px;float: left;">ถึง</div>
                                        <input id="endDate" name="endDate" class="form-control input-md" type="text" style="width:auto;float:left;margin-right: 5px;width: 100px;">
                                    </div>
                                </div>
                                
                                <div id="memberMap">
                                    <div id="map-canvas"></div>
                                </div>
                                
                                <div class="form-group">
                                    <label class="col-md-4 control-label" for=""></label>
                                    <div class="col-md-4">
                                        <input type='button' id="" name="" class="btn btn-primary" style="float: right;" value='บันทึก'
                                            onclick='formSubmit();'
                                            >
                                    </div>
                                </div>
                            </fieldset>
                        </form>
                    </div>
                </div>
            </td>
        </tr>
    </table>
</div>
<script type="text/javascript">
    $(function() {
        $( "#startDate" ).datepicker( $.datepicker.regional["th"] ); // Set ภาษาที่เรานิยามไว้ด้านบน
        $( "#startDate" ).datepicker("setDate", new Date()); //Set ค่าวันปัจจุบัน
        
        $( "#endDate" ).datepicker( $.datepicker.regional["th"] ); // Set ภาษาที่เรานิยามไว้ด้านบน
        $( "#endDate" ).datepicker("setDate", new Date()); //Set ค่าวันปัจจุบัน
    });
</script>